// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
import 'package:junyeyishu/ui/sale/widgets/QGSaleTypeSwitchWidget.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGListState.dart';
import 'package:junyeyishu/widgets/QGNavigationBar.dart';

import 'widgets/QGSaleBuyCell.dart';
import 'widgets/QGSaleBuyRecordCell.dart';

class QGSaleBuyListPage extends StatefulWidget {
  dynamic data;
  QGSaleBuyListPage({super.key, required this.data});
  @override
  State<QGSaleBuyListPage> createState() => _QGSaleBuyListPageState();
}

class _QGSaleBuyListPageState extends QGListState<QGSaleBuyListPage> {
  int type = 0;
  int finishNum = 0;
  int askNum = 0;

  @override
  void initState() {
    super.initState();

    listURL = url_market_tradeLogList;
    listKey = "list";
    isnopage = false;
    onRefresh();
  }

  @override
  listParam() {
    Map param = {"pid": widget.data['pid']};
    return param;
  }

  @override
  onResponse(res) {
    finishNum = res.ret["data"]?["finished_num"];
    askNum = res.ret["data"]?["cur_ask_num"];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // backgroundColor: Color(0xFFF8F8F6),
        body: Column(
          children: [
            buildHeader(),
            Row(
              children: [
                SizedBox(width: 15,),
                Text('今日成交数量: ',style: TextStyle(fontSize: 16,color: Color(0XFFFFFFFF))),
                Text('$finishNum',style: TextStyle(fontSize: 16,color: Color(0XFFFFFFFF))),
              ],
            ),

            buildListContainer(),
          ],
        ));
  }

  buildHeader() {
    return Column(children: [
      Container(
          // color: Color(0xFFFFFFFF),
          child: QGNavigationBar(title: widget.data['name'])),
      // SizedBox(height: 10.rpx),
      // SingleChildScrollView(
      //   child: Container(
      //     decoration: BoxDecoration(
      //         borderRadius: BorderRadius.circular(6.rpx),
      //         color: Color(0xFFFFFFFF)),
      //     margin: EdgeInsets.symmetric(horizontal: 10.rpx),
      //     child: QGSaleTypeSwitchWidget(
      //         alignment: MainAxisAlignment.center,
      //         current: type,
      //         items: ["成交记录", "当前求购"],
      //         nums: [finishNum, askNum],
      //         underline: true,
      //         onSwitch: onSwitch),
      //   ),
      // ),
    ]);
  }

  buildListContainer() {
    return Expanded(
      child: Container(
          margin: EdgeInsets.all(10.rpx),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(6.rpx),
              color: Color(0xFF232A32)),
          child: Column(
            children: [buildList(),
            SizedBox(height: 15.rpx,),
            Text('仅展示20条',style: TextStyle(fontSize: 16,color: Color(0XFFFFFFFF))),
            ],
          )),
    );
  }

  onSwitch(index) {
    type = index;
    list = null;
    if (index == 1) {
      listURL = url_ask_curList;
      listKey = "list";
    } else {
      listURL = url_market_tradeLogList;
      listKey = "list";
    }

    setState(() {});
    onRefresh();
  }

  @override
  itemBuilder(context, index, data) {
    data ??= {};
    data["type"] = type;

    if (type == 1) {
      return QGSaleBuyRecordCell(data: data ?? {});
    }

    return QGSaleBuyCell(data: data);
  }
}
